#include <qwt_plot_zoomer.h>

#include "SoundPlot.h"
#include "RawSoundPlot.h"

class Zoomer: public QwtPlotZoomer
{
	public:
		Zoomer(int xAxis, int yAxis, QwtPlotCanvas *canvas):QwtPlotZoomer(xAxis, yAxis, canvas)
		{
			setSelectionFlags(QwtPicker::DragSelection | QwtPicker::CornerToCorner);
			setTrackerMode(QwtPicker::AlwaysOff);
			setRubberBand(QwtPicker::NoRubberBand);

			setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
			setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
		}
};

SoundPlot::SoundPlot(SoundObj *so, long channel, QWidget *parent):QMainWindow(parent),soundO(so)
{
	d_plot = new RawSoundPlot(so, channel, this);
	d_plot->setMargin(5);

	setContextMenuPolicy(Qt::NoContextMenu);

	d_zoomer = new Zoomer( QwtPlot::xBottom, QwtPlot::yLeft, d_plot->canvas());
	d_zoomer->setRubberBand(QwtPicker::RectRubberBand);
	d_zoomer->setRubberBandPen(QColor(Qt::green));
	d_zoomer->setTrackerMode(QwtPicker::ActiveOnly);
	d_zoomer->setTrackerPen(QColor(Qt::green));

	d_plot->setMaximumSize(maxWidth, maxHeight);
	d_plot->setMinimumSize(minWidth, minHeight);
	setCentralWidget(d_plot);
}

void SoundPlot::enableZoomMode(bool on)
{
	d_zoomer->setEnabled(on);
	d_zoomer->zoom(0);
}

void SoundPlot::rebuildBlocByChannel(int id)
{
	this->d_plot = new RawSoundPlot(this->soundO, id+1, this);
	setCentralWidget(d_plot);
}

SoundPlot::~SoundPlot()
{
}
